<template>
  <div class="control-item">
    <div class="control-header">
      <span class="control-name">商品展示</span>
      <span @click="showBeautyBox = true">组件美化</span>
    </div>
    <div class="control-body">
      <div class="control-section">
        <!-- 模板样式 -->
        <div class="control-item">
          <div class="control-title">模板样式</div>
          <div class="control-content">
            <div class="example-list">
              <div
                class="example-item"
                v-for="(item, index) in exampleList"
                @click="setStyleType(item)"
                :class="goodsType == item.value ? 'active' : ''"
                :key="index"
              >
                <img :src="item.icon" alt="" />
              </div>
            </div>
          </div>
        </div>
        <!-- 展示内容 -->
        <div class="control-item content-show">
          <div class="control-title flex-between">
            <span>展示内容</span>
            <span class="reset" @click="resetItem('contentShow')">重置</span>
          </div>
          <div class="control-content">
            <div class="switch-item">
              <span>商品原价</span>
              <a-switch
                :default-checked="params.params.showPrice"
                @change="
                  (e) => {
                    setWithActionItem(e, 'showPrice');
                  }
                "
              />
            </div>
            <div class="switch-item">
              <span>商品销量</span>
              <a-switch
                :default-checked="params.params.showSales"
                @change="
                  (e) => {
                    setWithActionItem(e, 'showSales');
                  }
                "
              />
            </div>
            <div class="switch-item">
              <span>购买按钮</span>
              <a-switch
                :default-checked="params.params.showBuyBtn"
                @change="
                  (e) => {
                    setWithActionItem(e, 'showBuyBtn');
                  }
                "
              />
            </div>
          </div>
        </div>
        <!-- 购买模板样式 -->
        <div class="control-item">
          <div class="control-title">购买模板样式</div>
          <div class="control-content">
            <div class="buy-style-list">
              <div
                class="buy-item"
                v-for="(item, index) in buyStyleList"
                @click="setWithActionItem(item, 'buyStyle')"
                :class="buyStyle == item ? 'active' : ''"
                :key="index"
              >
                <i v-if="item == 'cart'" class="iconfont icon-weibiaoti-14"></i>
                <div v-if="item == 'add'" class="add-box">
                  <i class="iconfont icon-jiahao"></i>
                </div>
                <div v-if="item == 'word'" class="word-box">
                  <span class="white"></span>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- 按钮文案 -->
        <div class="control-item" v-if="buyStyle == 'word'">
          <div class="control-title">按钮文案</div>
          <div class="control-content buyBtnText">
            <a-input
              placeholder="请输入按钮文案"
              v-model="params.params.buyBtnText"
            />
          </div>
        </div>
        <!-- 商品外间距 -->
        <div class="control-item product-space">
          <div class="control-title">
            <span>商品外间距</span>
            <span class="reset" @click="resetItem('goodsItemOutSpace')"
              >重置</span
            >
          </div>
          <div class="control-content space-set">
            <div class="space-set-body">
              <i class="iconfont icon-xiajianju"></i>
              <a-slider
                class="slider"
                v-model="params.params.goodsItemOutSpace"
                :min="0"
                :max="20"
              />
              <div
                @mouseenter="showBoxOutSet = !showBoxOutSet"
                @mouseleave="showBoxOutSet = !showBoxOutSet"
              >
                <a-input-number
                  v-show="showBoxOutSet"
                  class="slider-input"
                  :min="0"
                  :max="50"
                  v-model="params.params.goodsItemOutSpace"
                />
                <span class="borderNumSpan" v-show="!showBoxOutSet">{{
                  params.params.goodsItemOutSpace || 0
                }}</span>
                <span>px</span>
              </div>
            </div>
          </div>
        </div>
        <!-- 商品内间距 -->
        <div class="control-item product-space">
          <div class="control-title">
            <span>商品内间距</span>
            <span class="reset" @click="resetItem('goodsItemInnerSpace')"
              >重置</span
            >
          </div>
          <div class="control-content space-set">
            <div class="space-set-body">
              <i class="iconfont icon-zuoyoujianju"></i>
              <a-slider
                class="slider"
                v-model="params.params.goodsItemInnerSpace"
                :min="0"
                :max="20"
              />
              <div
                @mouseenter="showBoxInnerSet = !showBoxInnerSet"
                @mouseleave="showBoxInnerSet = !showBoxInnerSet"
              >
                <a-input-number
                  v-show="showBoxInnerSet"
                  class="slider-input"
                  :min="0"
                  :max="50"
                  v-model="params.params.goodsItemInnerSpace"
                />
                <span class="borderNumSpan" v-show="!showBoxInnerSet">{{
                  params.params.goodsItemInnerSpace || 0
                }}</span>
                <span>px</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 组件美化 -->
    <comBeautyBox
      :showBeautyBox="showBeautyBox"
      @handleBack="showBeautyBox = false"
    >
      <div>
        <!-- 背景配置 -->
        <bgControl :backgroudData="params.params.goodsBgCss"></bgControl>
        <!-- 间距控制组件 -->
        <spaceControl
          :spaceData.sync="params.params.goodsBgCss"
          @resetSpace="resetSpace"
          @resetMp="resetMp"
        ></spaceControl>
        <!-- 商品标题颜色设置 -->
        <div class="color-control-item">
          <div
            class="color-control-head"
            :class="!producNameColor ? 'no-padding-bottom' : ''"
          >
            <p>商品标题</p>
            <div class="head-icons">
              <i
                class="iconfont icon-xianshi"
                @click.stop="resetItem('producNameColor')"
              ></i>
              <i
                v-if="!producNameColor"
                @click.stop="producNameColor = !producNameColor"
                class="iconfont icon-jiahao"
              ></i>
              <i
                v-else
                @click.stop="producNameColor = !producNameColor"
                class="iconfont icon-jian"
              ></i>
            </div>
          </div>
          <colorControl
            v-if="producNameColor"
            :color.sync="params.params.producNameColor"
            title="商品标题"
            :showControlHeader="false"
            @reset="resetItem('producNameColor')"
            @change="
              (e) => {
                setColorItem('producNameColor', e);
              }
            "
          ></colorControl>
        </div>
        <!-- 商品价格颜色设置 -->
        <div class="color-control-item">
          <div
            class="color-control-head"
            :class="!priceColor ? 'no-padding-bottom' : ''"
          >
            <p>商品价格</p>
            <div class="head-icons">
              <i
                class="iconfont icon-xianshi"
                @click.stop="resetItem('priceColor')"
              ></i>
              <i
                v-if="!priceColor"
                @click.stop="priceColor = !priceColor"
                class="iconfont icon-jiahao"
              ></i>
              <i
                v-else
                @click.stop="priceColor = !priceColor"
                class="iconfont icon-jian"
              ></i>
            </div>
          </div>
          <colorControl
            v-if="priceColor"
            :showControlHeader="false"
            :color.sync="params.params.priceColor"
            title="商品价格"
            @reset="resetItem('priceColor')"
            @change="
              (e) => {
                setColorItem('priceColor', e);
              }
            "
          ></colorControl>
        </div>
        <!-- 商品原价颜色设置 -->
        <div class="color-control-item">
          <div
            class="color-control-head"
            :class="!originPriceColor ? 'no-padding-bottom' : ''"
          >
            <p>商品原价</p>
            <div class="head-icons">
              <i
                class="iconfont icon-xianshi"
                @click.stop="resetItem('originPriceColor')"
              ></i>
              <i
                v-if="!originPriceColor"
                @click.stop="originPriceColor = !originPriceColor"
                class="iconfont icon-jiahao"
              ></i>
              <i
                v-else
                @click.stop="originPriceColor = !originPriceColor"
                class="iconfont icon-jian"
              ></i>
            </div>
          </div>
          <colorControl
            v-if="originPriceColor"
            :showControlHeader="false"
            :color.sync="params.params.originPriceColor"
            title="商品原价"
            @reset="resetItem('originPriceColor')"
            @change="
              (e) => {
                setColorItem('originPriceColor', e);
              }
            "
          ></colorControl>
        </div>
        <!-- 商品销量颜色设置 -->
        <div class="color-control-item">
          <div
            class="color-control-head"
            :class="!saleColor ? 'no-padding-bottom' : ''"
          >
            <p>商品销量</p>
            <div class="head-icons">
              <i
                class="iconfont icon-xianshi"
                @click.stop="resetItem('saleColor')"
              ></i>
              <i
                v-if="!saleColor"
                @click.stop="saleColor = !saleColor"
                class="iconfont icon-jiahao"
              ></i>
              <i
                v-else
                @click.stop="saleColor = !saleColor"
                class="iconfont icon-jian"
              ></i>
            </div>
          </div>
          <colorControl
            v-if="saleColor"
            :showControlHeader="false"
            :color.sync="params.params.saleColor"
            title="商品销量"
            @reset="resetItem('saleColor')"
            @change="
              (e) => {
                setColorItem('saleColor', e);
              }
            "
          ></colorControl>
        </div>
      </div>
    </comBeautyBox>
  </div>
</template>

<script>
import productDefault from "@/assets/images/diy/product/product_full.png";
import productFlexTwo from "@/assets/images/diy/product/product_flex_two.png";
import productCoulmTwo from "@/assets/images/diy/product/product_coulm_two.png";
import productFlexThree from "@/assets/images/diy/product/product_flex_three.png";

import { productShow } from "@/components/DiyNew/diy/dataConfig/config.js";
import colorControl from "@/components/DiyNew/diy/baseControl/colorControl/index.vue";
import bgControl from "@/components/DiyNew/diy/baseControl/bgControl/index.vue";
import spaceControl from "@/components/DiyNew/diy/baseControl/spaceControl/index.vue";

import comBeautyBox from "@/components/DiyNew/diy/comBeautyBox/comBeautyBox.vue";

export default {
  name: "productShowControl",
  components: {
    colorControl,
    comBeautyBox,
    bgControl,
    spaceControl,
  },
  props: {
    params: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      showBeautyBox: false,
      exampleList: [
        {
          icon: productDefault,
          type: "模板1",
          value: "1",
        },
        {
          icon: productFlexTwo,
          type: "模板2",
          value: "2",
        },
        {
          icon: productCoulmTwo,
          type: "模板3",
          value: "3",
        },
        {
          icon: productFlexThree,
          type: "模板4",
          value: "4",
        },
      ],
      showGoods: false,
      catList: [],
      buyStyleList: ["cart", "add", "word"],
      producNameColor: false,
      priceColor: false,
      originPriceColor: false,
      saleColor: false,
      showBoxOutSet: false,
      showBoxInnerSet: false,
    };
  },
  watch: {},
  computed: {
    goodsType: {
      get() {
        return this.params.params.goodsType || "1";
      },
    },
    buyStyle: {
      get() {
        return this.params.params.buyStyle || "add";
      },
    },
  },
  mounted() {
    if (this.params.params.styleType == 2) {
      this.exampleList.pop(this.exampleList.length - 1);
    }
  },
  methods: {
    // 设置样式
    setStyleType(item) {
      this.$setWithAction(this.params, "goodsType", item.value);
    },
    setWithActionItem(e, key) {
      this.$setWithAction(this.params, key, e);
    },
    // 点击重置按钮
    resetItem(type) {
      let data = Object.assign({}, productShow);
      console.log(data);
      if (type == "contentShow") {
        this.$set(
          this.params.params,
          "showPrice",
          productShow.params.showPrice
        );
        this.$set(
          this.params.params,
          "showSales",
          productShow.params.showSales
        );
        this.$set(
          this.params.params,
          "showBuyBtn",
          productShow.params.showBuyBtn
        );
        return;
      }
      this.$set(this.params.params, type, data.params[type]);
    },
    // 颜色设置回调
    setColorItem(type, color) {
      console.log(type, color);
      this.$set(this.params.params, type, color);
    },
    // 重置圆角
    resetSpace(e) {
      let type = e.type;
      console.log(type);
      this.$set(this.params.goodsBgCss, type, 0);
    },
    // 重置边距
    resetMp() {
      this.$set(this.params.goodsBgCss, "margin", 0);
      this.$set(this.params.goodsBgCss, "padding", 0);
    },
  },
};
</script>

<style lang="scss" scoped>
.control-item {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  .control-header {
    width: 100%;
    height: 48px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px 14px 24px;
    span {
      font-size: 12px;
      color: #8c8c8c;
    }
    .control-name {
      font-size: 14px;
      font-weight: 600;
      color: #000000;
    }
    span:nth-child(2) {
      cursor: pointer;
    }
  }
  .control-body {
    width: 100%;
    padding-bottom: 20px;
    .control-section {
      width: 228px;
      margin: 0 auto;
      text-align: center;
      .control-item {
        width: 100%;
        .control-title {
          padding: 24px 0 14px 0;
          font-size: 12px;
          color: #000000;
          text-align: left;
        }
        .control-content {
          .example-list {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            .example-item {
              width: 70px;
              height: 70px;
              background: #f6f7f9;
              border-radius: 4px;
              margin-right: 6px;
              margin-bottom: 8px;
              display: flex;
              justify-content: center;
              align-items: center;
              cursor: pointer;
              img {
                width: 70px;
                height: 70px;
              }
            }
            .example-item:last-child {
              margin-right: 0;
            }
            .active {
              border: 2px solid #1890fc;
            }
          }
          .buy-style-list {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            .buy-item {
              width: 70px;
              height: 44px;
              background: #f6f7f9;
              border-radius: 4px;
              display: flex;
              justify-content: center;
              align-items: center;
              margin-right: 8px;
              cursor: pointer;
              .icon-weibiaoti-14 {
                font-size: 22px;
              }
              .add-box {
                width: 24px;
                height: 24px;
                background: #444444;
                border-radius: 8px;
                display: flex;
                justify-content: center;
                align-items: center;
                .iconfont {
                  font-size: 23px;
                  color: #ffffff;
                }
              }
              .word-box {
                width: 42px;
                height: 24px;
                background: #444444;
                border-radius: 60px;
                position: relative;
                .white {
                  width: 20px;
                  height: 6px;
                  background: #ffffff;
                  border-radius: 30px;
                  position: absolute;
                  left: 11px;
                  top: 9px;
                }
              }
            }
            .buy-item:last-child {
              margin-right: 0;
            }
            .active {
              border: 2px solid #1890fc;
            }
          }
        }
        .buyBtnText {
          width: 226px;
          height: 40px;
          border-radius: 4px;
          ::v-deep .ant-input {
            width: 100%;
            height: 100%;
            border: 0 none;
            background: #f6f7f9;
          }
        }

        .space-set {
          .space-set-body {
            width: 100%;
            height: 40px;
            background: #f6f7f9;
            border-radius: 4px;
            display: flex;
            align-items: center;
            padding-left: 14px;
            .iconfont {
              font-size: 20px;
            }
            .slider {
              margin: 0 16px;
              width: 100px;
              ::v-deep .ant-slider-track {
                background-color: #1890fc;
              }
              ::v-deep .ant-slider-rail {
                background-color: #e6e6e6;
              }
            }
            .slider-input {
              width: 30px;
              font-size: 12px;
              background-color: #f6f7f9;
              ::v-deep .ant-input-number-input {
                padding: 0;
                padding-right: 5px;
                text-align: right;
              }
            }
            span {
              font-size: 12px;
              color: #000000;
            }
            .borderNumSpan {
              width: 30px;
              display: inline-block;
              text-align: right;
              padding-right: 5px;
              border: 1px solid #f6f7f9;
            }
            ::v-deep .ant-input-number-handler-wrap {
              display: none;
            }
          }
        }
      }
      .title-section {
        .flex-between {
          display: flex;
          justify-content: space-between;
          .reset {
            font-size: 12px;
            color: #9e9e9e;
            cursor: pointer;
          }
        }
        .control-content {
          display: flex;
          align-items: center;
          .title-name-input {
            width: 196px;
            height: 40px;
            border-radius: 4px;
            input {
              height: 100%;
              background-color: #f6f7f9;
              border: 0 none;
            }
          }
          .hidden-icon {
            width: 24px;
            height: 24px;
            background: #f6f7f9;
            border-radius: 4px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 16px;
            margin-left: 8px;
            cursor: pointer;
          }
        }
      }

      .content-show {
        .flex-between {
          display: flex;
          justify-content: space-between;
          .reset {
            font-size: 12px;
            color: #9e9e9e;
            cursor: pointer;
          }
        }
        .control-content {
          .switch-item {
            width: 228px;
            height: 40px;
            background: #f6f7f9;
            border-radius: 4px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 14px;
            margin-bottom: 8px;
          }
          .switch-item:last-child {
            margin-bottom: 0;
          }
        }
      }

      .choose-product {
        .flex-between {
          display: flex;
          justify-content: space-between;
          .reset {
            font-size: 12px;
            color: #9e9e9e;
            cursor: pointer;
          }
        }
        .control-content {
          .data-tabs {
            width: 228px;
            height: 34px;
            background: #f6f7f9;
            border-radius: 4px;
            position: relative;
            .tab-bg {
              width: 113px;
              height: 30px;
              background: #ffffff;
              opacity: 1;
              border-radius: 4px;
              position: absolute;
              left: 2px;
              top: 2px;
              z-index: 11;
              transition: all 0.2s;
            }
            .active-select {
              left: 2px;
            }
            .active-classify {
              left: 113px;
            }
            .tab-content {
              width: 100%;
              height: 100%;
              position: absolute;
              left: 0;
              top: 0;
              z-index: 12;
              display: flex;
              justify-content: center;
              align-items: center;
              .tab-item {
                flex: 1;
                display: flex;
                justify-content: center;
                align-items: center;
                font-size: 14px;
                font-weight: 400;
                color: #000000;
                opacity: 0.45;
                transition: all 0.2s;
                cursor: pointer;
                user-select: none;
              }
            }
          }
          .select-data-section {
            margin-top: 8px;
          }
          .select-data {
            width: 228px;
            height: 40px;
            background: #f6f7f9;
            border-radius: 4px;
            padding: 0 14px;
            display: flex;
            align-items: center;
            cursor: pointer;
            .iconfont {
              font-size: 18px;
            }
            span {
              font-size: 14px;
              font-family: PingFang SC;
              font-weight: 400;
              color: #000000;
              margin-left: 8px;
            }
          }
          .select-list {
            width: 224px;
            background: #ffffff;
            border: 2px solid #f6f7f9;
            max-height: 320px;
            overflow: auto;
            display: flex;
            flex-direction: column;
            align-items: center;
            box-sizing: content-box;
            .list-item {
              display: flex;
              align-items: center;
              padding: 0 14px;
              width: 100%;
              height: 64px;
              flex-shrink: 0;
              .pic-img {
                width: 44px;
                height: 44px;
                background: #ffffff;
                border-radius: 4px;
                margin-right: 6px;
                flex-shrink: 0;
              }
              .name {
                width: 98px;
                height: 20px;
                font-size: 14px;
                font-family: PingFang SC;
                font-weight: 400;
                color: #000000;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                margin-right: 10px;
                margin-bottom: 0;
              }
              .action {
                margin-bottom: 0;
                position: relative;
                width: 16px;
                height: 24px;
                .iconfont {
                  position: absolute;
                  top: 0;
                }
                .iconfont:nth-child(1) {
                  left: -4px;
                }
                .iconfont:nth-child(2) {
                  right: -4px;
                }
                .disabled {
                  color: #a6a6a6;
                }
              }
              .delete {
                font-size: 12px;
                margin-bottom: 0;
                margin-left: 10px;
              }
            }
          }
          .select-classify {
            width: 228px;
            height: 40px;
            background: #f6f7f9;
            border-radius: 4px;
            margin-top: 8px;
            ::v-deep .ant-select-selection {
              height: 40px;
              border: 0 none;
              background: #f6f7f9;
            }
            ::v-deep .ant-select-selection__rendered {
              line-height: 40px;
            }
          }
        }
      }

      .product-space {
        .control-title {
          display: flex;
          justify-content: space-between;
          align-items: center;
          .reset {
            font-size: 12px;
            color: #9e9e9e;
            cursor: pointer;
          }
        }
      }
    }
  }
}
.color-control-item {
  width: 100%;
  padding-bottom: 20px;
  border-bottom: 1px solid #f0f2f5;
  .color-control-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 400;
    color: #000000;
    padding: 24px 0 12px 0;
    p {
      margin-bottom: 0;
    }
    .head-icons {
      .iconfont:nth-child(1) {
        margin-right: 5px;
      }
    }
  }
  .no-padding-bottom {
    padding-bottom: 0;
  }
}
</style>
